﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

/** 
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
 * Description: 
 * Author: Heller (HellerSong@outlook.com)
 * CreationTime: 4/9/2015 9:45:25 PM
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 
 **/
namespace DevGrammar
{
	[TestClass]
	public class TestDateTime
	{
		[TestMethod]
		public void test_current_time()
		{
			Console.WriteLine("Current Time is: " + DateTime.Now);
			Console.WriteLine(Environment.TickCount/1000/60);	// Get the millisecond of duration PC from start to now
		}

		[TestMethod]
		public void test_format_date_time()
		{
			// MM should not mm
			// HH 24 hour; hh 12 hour
			Console.WriteLine(DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
			Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd"));
			Console.WriteLine(DateTime.Now.ToLongDateString().ToString());		// Thursday, April 9, 2015

		}

		[TestMethod]
		public void test_each_part_of_date_time()
		{
			DateTime dtNow = DateTime.Now;
			Console.WriteLine(dtNow.ToShortDateString().ToString());	// 4/10/2015
			Console.WriteLine(dtNow.ToShortTimeString().ToString());	// 8:04 AM

			Console.WriteLine("Month is: " + dtNow.Month.ToString());
			Console.WriteLine("Day is: " + dtNow.Day.ToString());
			Console.WriteLine("Year is: " + dtNow.Year.ToString());
			Console.WriteLine("Hour is: " + dtNow.Hour.ToString());
			Console.WriteLine("Minute is: " + dtNow.Minute.ToString());
			Console.WriteLine("Second is: " + dtNow.Second.ToString());
			Console.WriteLine(dtNow.DayOfWeek.ToString());	// Thursday
			Console.WriteLine(dtNow.DayOfYear.ToString());	// 4/10/2015 --> 100
		}

		[TestMethod]
		public void test_date_count()
		{
			/* Count days have among which year and in which month */
			int days = DateTime.DaysInMonth(2015, 4);
			Console.WriteLine("Days Count is: " + days);


			/* Add a day or sub a day */
			DateTime dt = DateTime.Now;
			dt.AddDays(1);	// Add a day, dt itself is not changed
			dt.AddDays(-1);	// Sub a day, dt itself is not changed

		}

		[TestMethod]
		public void test()
		{
			//Console.WriteLine(dt.ToFileTime().ToString());   //   129036792908014024
			//// Converts the value of the current System.DateTime object to a Windows file time
			//Console.WriteLine(dt.ToFileTimeUtc().ToString());  //     129036792908014024
			//// Converts the value of the current System.DateTime object to a Windows file time
			//Console.WriteLine(dt.ToLocalTime().ToString());   //       26/11/2009 AM 11:21:30


			//Console.WriteLine(dt.CompareTo(dt).ToString());    //       0
			//Console.WriteLine(dt.Add(new TimeSpan(1,0,0,0)).ToString());    // 加上一个时间段
			//（注：
			//System.TimeSpan为一个时间段，构造函数如下
			//public TimeSpan(long ticks); // ticks: A time period expressed in 100-nanosecond units.
			//                           //nanosecond：十亿分之一秒   new TimeSpan(10,000,000)        为一秒
			//public TimeSpan(int hours, int minutes, int seconds);
			//public TimeSpan(int days, int hours, int minutes, int seconds);
			//public TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds);
			//）
			//Console.WriteLine(dt.Equals("2005-11-6 16:11:04").ToString());     //        False
			//Console.WriteLine(dt.Equals(dt).ToString());    //      True
			//Console.WriteLine(dt.GetHashCode().ToString());    //       1103291775
			//Console.WriteLine(dt.GetType().ToString());    //       System.DateTime
			//Console.WriteLine(dt.GetTypeCode().ToString());    //       DateTime

			//long Start = Environment.TickCount;   //单位是毫秒
			//long End = Environment.TickCount;
			//Console.WriteLine("Start is : "+Start);
			//Console.WriteLine("End is : "+End);
			//Console.WriteLine("The Time is {0}",End-Start);
			//Console.WriteLine(dt.GetDateTimeFormats('s')[0].ToString());    //2009-11-26T13:29:06
			//Console.WriteLine(dt.GetDateTimeFormats('t')[0].ToString());    //PM 1:29
			//Console.WriteLine(dt.GetDateTimeFormats('y')[0].ToString());    //2009年11月
			//Console.WriteLine(dt.GetDateTimeFormats('D')[0].ToString());    //2009年11月26日
			//Console.WriteLine(dt.GetDateTimeFormats('D')[1].ToString());    //星期四, 26 十一月, 2009
			//Console.WriteLine(dt.GetDateTimeFormats('D')[2].ToString());    //26 十一月, 2009
			//Console.WriteLine(dt.GetDateTimeFormats('D')[3].ToString());    //星期四 2009 11 26
			//Console.WriteLine(dt.GetDateTimeFormats('M')[0].ToString());    //26 十一月
			//Console.WriteLine(dt.GetDateTimeFormats('f')[0].ToString());    //2009年11月26日 PM 1:29
			//Console.WriteLine(dt.GetDateTimeFormats('g')[0].ToString());    //26/11/2009 PM 1:29
			//Console.WriteLine(dt.GetDateTimeFormats('r')[0].ToString());    //Thu, 26 Nov 2009 13:29:06 GMT
			//(注：
			//常用的日期时间格式：
			//格式 说明      输出格式 
			//d 精简日期格式 MM/dd/yyyy 
			//D 详细日期格式 dddd, MMMM dd, yyyy 
			//f  完整格式    (long date + short time) dddd, MMMM dd, yyyy HH:mm 
			//F 完整日期时间格式 (long date + long time) dddd, MMMM dd, yyyy HH:mm:ss 
			//g 一般格式 (short date + short time) MM/dd/yyyy HH:mm 
			//G 一般格式 (short date + long time) MM/dd/yyyy HH:mm:ss 
			//m,M 月日格式 MMMM dd 
			//s 适中日期时间格式 yyyy-MM-dd HH:mm:ss 
			//t 精简时间格式 HH:mm 
			//T 详细时间格式 HH:mm:ss
			//)

			//Console.WriteLine(string.Format("{0:d}", dt));    //28/12/2009
			//Console.WriteLine(string.Format("{0:D}", dt));    //2009年12月28日
			//Console.WriteLine(string.Format("{0:f}", dt));    //2009年12月28日 AM 10:29
			//Console.WriteLine(string.Format("{0:F}", dt));    //2009年12月28日 AM 10:29:18
			//Console.WriteLine(string.Format("{0:g}", dt));    //28/12/2009 AM 10:29
			//Console.WriteLine(string.Format("{0:G}", dt));    //28/12/2009 AM 10:29:18
			//Console.WriteLine(string.Format("{0:M}", dt));    //28 十二月
			//Console.WriteLine(string.Format("{0:R}", dt));    //Mon, 28 Dec 2009 10:29:18 GMT
			//Console.WriteLine(string.Format("{0:s}", dt));    //2009-12-28T10:29:18
			//Console.WriteLine(string.Format("{0:t}", dt));    //AM 10:29
			//Console.WriteLine(string.Format("{0:T}", dt));    //AM 10:29:18
			//Console.WriteLine(string.Format("{0:u}", dt));    //2009-12-28 10:29:18Z
			//Console.WriteLine(string.Format("{0:U}", dt));    //2009年12月28日 AM 2:29:18
			//Console.WriteLine(string.Format("{0:Y}", dt));    //2009年12月
			//Console.WriteLine(string.Format("{0}", dt));    //28/12/2009 AM 10:29:18
			//Console.WriteLine(string.Format("{0:yyyyMMddHHmmssffff}", dt));    //200912281029182047

			//计算2个日期之间的天数差
			//DateTime dt1 = Convert.ToDateTime("2007-8-1");    
			//DateTime dt2 = Convert.ToDateTime("2007-8-15");   
			//TimeSpan span = dt2.Subtract(dt1);              
			//int dayDiff = span.Days ;                    
		}
	}
}
